<?php session_start();
validaAcesso(); ?>
<h2>Valores Arrecadados da Institui&ccedil;&atilde;o: <?php echo $_SESSION["NOME_HOSTEL_"]; ?></h2>
<?php
if($_GET["cont"]==1){


	$novo_datai=formataData($_POST["pdatai"], true);
	$novo_dataf=formataData($_POST["pdataf"], true);

/*
	if(!formaMulta("multapmidia")){
		$tipoCobranca = "<span style='font-weight:bold'>Forma de Cobrar Multa utilizada:</span> por dia de atraso, independente do n&uacute;mero de m&iacute;dias emprestadas.";
		$pordiaIndependente = true;

	}else{
		$tipoCobranca = "<span style='font-weight:bold'>Forma de Cobrar Multa utilizada:</span> por dia de atraso de cada m&iacute;dia emprestada.";
		$pordiaIndependente = false;

	}
*/
	echo "<div class='aviso'>$tipoCobranca</div>";




	$sql="
        select
            a.data_devolucao,
            a.pg,
            b.nome_membro,
            c.tombo,
            c.titulo,
            a.ref_membros,
            a.data_inicio,
            a.data_devolucao
          from

            bibl_emprestimos a
            inner join pes_pessoas b on (a.ref_quem_dev=b.cod_membro)
            left join bibl_midias c on (a.ref_midias=c.cod_midia)

          where
            (b.ref_inst = ". $_SESSION["ID_HOSTEL_"] .") and            
            (a.pg <> 0) and            
            (a.data_devolucao between   '$novo_datai' and '$novo_dataf')

          order by b.nome_membro asc, a.ref_quem_dev asc, a.data_devolucao asc
            ";
	$linha=$_SESSION['ADOCnn']->Execute("$sql");
	//            echo $sql; exit;
	$periodo = "Per&iacute;odo: ".formataData($novo_datai)." � ".formataData($novo_dataf);
	echo "<h2>$periodo</h2>
                    <table class='perfil'>
                    <tr class='titulo'>
                      <td>Data de Devolu&ccedil;&atilde;o</td>
                      <td>ID Membro</td>
                      <td>Tombo</td>
                      <td>T&iacute;tulo</td>
                      <td>Valor R$</td>
                    </tr>
                    ";
	$valor=0;

	$dadosGrafico = "";
	$class="odd";

	if($linha->RecordCount() != 0 ){
		while(!$linha->EOF){


			$ant_nome="$nome";
			$ant_data = $mes;

			$ant_data_inicio    = $data_inicio;
			$ant_data_devolucao = $data_devolucao;
			$ant_id_membro	  = $id_membro;

			$data 		= formataData($linha->fields[0]);
			$mes 			= substr($data,3,2);

			$pg   		= $linha->fields[1];
			$nome 		= trim($linha->fields[2]);
			$tombo		= $linha->fields[3];
			$titulo		= $linha->fields[4];
			$id_membro	= $linha->fields[5];
			$data_inicio	= $linha->fields[6];
			$data_devolucao= $linha->fields[7];



			if($ant_nome != $nome){
				echo"<tr><td colspan=4><u>Funcion&aacute;rio:</u> <b>$nome</b></td></tr>";
				$dadosGrafico .= "<set name='$ant_nome' value='$valorParcial' color='".getFCColor()."'/>";
				$valorParcial = 0;
			}


			$valorParcial += $pg;

			if ($pordiaIndependente == true) {


				if (
				$ant_data_inicio == $data_inicio &&
				$ant_data_devolucao == $data_devolucao &&
				$ant_id_membro == $id_membro) {

					$pg = 0;
				}else {
					if($class == "odd"){$class="even";}else{$class="odd";}
				}
			}else {
				if($class == "odd"){$class="even";}else{$class="odd";}
			}


			echo"
                    <tr class='$class'>
                      <td>$data</td>
                      <td>$id_membro</td>
                      <td>$tombo</td>
                      <td>$titulo</td>
                      <td class='dindin'>".formataValor($pg,false,false)."</td>
                    </tr>
                   ";
			$valor+=$pg;




			$linha->MoveNext();
		}
	}
	$dadosGrafico .= "<set name='$nome' value='$valorParcial' color='".getFCColor()."'/>";
	echo"<tr><td class='dindin' colspan=4><b>Total:</b> <u>".formataValor($valor, true,false)." reais</u></td></tr></table> ";






	###inicio grafico #####################

	$w = 740;
	$h = 440;

	$head = "<graph caption='$periodo' xAxisName='' yAxisName='Valores' numberPrefix='R$ ' decimalPrecision='2' formatNumberScale='0' chartRightMargin='20' showNames='1' pieFillAlpha='100' pieSliceDepth='85' pieRadius='200' pieYScale='70'  rotateNames='1'>";


	echo "
		<div align='left'>
		  <OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='$w' height='$h' id='Column3D' >
		    <param name='movie' value='admin/fusion_charts/Charts/FCF_Column3D.swf' />
		    <param name='FlashVars' value=\"&chartWidth=$w&chartHeight=$h&dataXML=$head $dadosGrafico</graph>\">
		    <param name='quality' value='high' />
		    <embed src='admin/fusion_charts/Charts/FCF_Column3D.swf' flashVars=\"&chartWidth=$w&chartHeight=$h&dataXML=$head $categoriasGrafico $dadosGrafico</graph>\" quality='high' width='$w' height='$h' name='Grafico' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />
		  </object>
		  
		    <OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='$w' height='$h' id='Column3D' >
		    <param name='movie' value='admin/fusion_charts/Charts/FCF_Bar2D.swf' />
		    <param name='FlashVars' value=\"&chartWidth=$w&chartHeight=$h&dataXML=$head $dadosGrafico</graph>\">
		    <param name='quality' value='high' />
		    <embed src='admin/fusion_charts/Charts/FCF_Bar2D.swf' flashVars=\"&chartWidth=$w&chartHeight=$h&dataXML=$head $categoriasGrafico $dadosGrafico</graph>\" quality='high' width='$w' height='$h' name='Grafico' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />
		  </object>
		</div>
		
		";

	###fim grafico #####################






}else{
?>
            <script type="text/javascript" src="css2/calendar/dhtmlgoodies_calendar.js"></script>
            <form method='POST' action='index.jsp?rel=6&cont=1' autocomplete='off'>
            
              <b>Data Inicial:</b>
              <input type="text" value="<?php echo date("d/m/Y"); ?>" readonly name="pdatai"  id="pdatai" id="pdatai">
              <img src="images/data.gif" border="0" style="cursor:hand;" onclick="displayCalendar(document.getElementById('pdatai'),'dd/mm/yyyy',this);">

              &nbsp;<b>Data Final:</b>
              <input type="text" value="<?php echo date("d/m/Y"); ?>" readonly name="pdataf"  id="pdataf" id="pdataf">
              <img src="images/data.gif" border="0" style="cursor:hand;" onclick="displayCalendar(document.getElementById('pdataf'),'dd/mm/yyyy',this);">


          <input type='submit' value='Gerar Estat&iacute;stica'>

        </form>
<?php
}
?>

